from django.db import models

class PledgedriveStation(models.Model):
    """
    Stations have call letters
    # Create a station
    >>> kbaq = PledgedriveStation.objects.create(station_title="KBAQ", station_phone="444-444-4444", station_url="http://kbaq.org")
    >>> kunc = PledgedriveStation.objects.create(station_title="KUNC", station_phone="555-555-5555", station_url="http://kunc.org")

    # Create a list of stations
    >>> stations_list = PledgedriveStation.objects.all()
    >>> print stations_list
    [<PledgedriveStation: KBAQ>, <PledgedriveStation: KUNC>]
    """
    station_title = models.CharField("Station Title", max_length=125)
    station_phone = models.CharField("Station Phone", max_length=125, blank=True)
    station_url = models.CharField("Station URL", max_length=125, blank=True)
    def __unicode__(self):
       return u'%s' % (self.station_title)


class PledgedriveProgram(models.Model):
    """
    Stations have programs
    # Create programs
    >>>
    >>>

    # Create a list of programs
    >>>

    """
    station_id = models.ForeignKey(PledgedriveStation, verbose_name="Station")
    program_title = models.CharField("Program Title", max_length=125)
    external_id = models.CharField("External ID", max_length=125, blank=True)
    def __unicode__(self):
        return u'%s' % (self.program_title)

class PledgedriveSegment(models.Model):
    """
    Pledgedrives have pitch segments
    # Create segments
    >>>
    >>>

    # Create a list of segments
    >>>

    """
    # producer_id = models.ForeignKey(PledgedriveWorker, verbose_name="Producer")
    # guest_id = models.IntegerField(null=True, blank=True)
    program_id = models.ForeignKey('PledgedriveProgram', verbose_name="Program")
    segment_start_time = models.DateTimeField(null=True, blank=True)
    segment_end_time = models.DateTimeField(null=True, blank=True)
    def __unicode__(self):
        return u'%s' % (self.segment_start_time)
class PledgedriveDrive(models.Model):
    """
    Pledgedrives are inevitable
    # Create pledgedrives
    >>>
    >>>

    # Create a list of pledgedrives
    >>>

    """
    station_id = models.ForeignKey(PledgedriveStation, verbose_name="Station")
    drive_title = models.CharField("Drive Title", max_length=125)
    station_id = models.ForeignKey(PledgedriveStation, verbose_name="Station")
    drive_dollar_goal = models.DecimalField(max_digits=10, decimal_places=2, null=True, blank=True)
    drive_pledge_goal = models.IntegerField(null=True, blank=True)
    segment_id = models.ManyToManyField(PledgedriveSegment, verbose_name="Segment")
    def __unicode__(self):
        return u'%s %s' % (self.station_id, self.drive_title)    

class PledgedriveWorker(models.Model):
    """
    Pledgedrives do not happen by themselves.  Pledgedrives have workers.  Stations have workers.
    # Create workers
    >>>
    >>>

    # Create a list of workers
    >>>

    """
    station = models.ForeignKey(PledgedriveStation, verbose_name="Station")
    first_name = models.CharField("First Name", max_length=125)
    last_name = models.CharField("Last Name", max_length=125)
    def __unicode__(self):
        return u'%s %s' % (self.first_name, self.last_name)
    
class PledgedriveDonor(models.Model):
    """
    Challenges have donors.  Donors are wonderful!
    # Create donors
    >>>
    >>>

    # Create a list of donors
    >>>

    """

    donor_first_name = models.CharField("First Name", max_length=125)
    donor_last_name = models.CharField("Last Name", max_length=125)
    def __unicode__(self):
        return u'%s %s' % (self.donor_first_name, self.donor_last_name)
    
class PledgedriveChallenge(models.Model):
    """
    Segments have challenges.  Challenges can be of different types.  Challenges are in different states of completion.
    # Create challenges
    >>>
    >>>

    # Create a list of challenges
    >>>

    """
    challenge_types = (
        ('0', 'Matching'), # if x $ is met full $ total of challenge is awarded
        ('1', 'Pledge'), # challenge is met if x pledges are achieved
        ('2', 'Bonus'), # x dollars added to each pledge up to x amount
    )
    challenge_states = (
        ('0', 'Pending'),
        ('1', 'Missed'),
        ('2', 'Achieved'),
        ('3', 'Recycled'),
    )
    challenge_title = models.CharField("Challenge Title", max_length=125)
    challenge_description = models.TextField(blank=True)
    challenge_state = models.IntegerField(choices=challenge_states,default="0")
    challenge_type = models.IntegerField(choices=challenge_types,default="0")
    challenge_pledge_goal = models.IntegerField(null=True, blank=True)
    challenge_dollar_goal = models.DecimalField(max_digits=6, decimal_places=2, null=True, blank=True)
    segment_id = models.ForeignKey(PledgedriveSegment, verbose_name="Segment")
    donation_id = models.ManyToManyField('PledgedriveDonation', verbose_name="Donation")

    def __unicode__(self):
        return u'%s' % (self.challenge_title)

class PledgedriveDonation(models.Model):
    """
    Challenges have donations.  Donations are made by donors. 
    # Create donations
    >>>
    >>>

    # Create a list of donations
    >>>

    """
    donation_status = (
        ('0', 'Public'),
        ('1', 'Anonymous'),
    )
    donation_amount = models.DecimalField(max_digits=8, decimal_places=2)
    donor_id = models.ForeignKey(PledgedriveDonor, verbose_name="Donor")
    donation_description = models.TextField(blank=True)
    privacy = models.IntegerField(choices=donation_status, default="0")
    def __unicode__(self):
        return u'%s' % (self.donation_amount)
    
class PledgedrivePledge(models.Model):
    """
    Pledgedrives generate pledges.  Workers take pledges.
    # Create pledges
    >>>
    >>>

    # Create a list of pledges
    >>>

    """
    tech_id = models.ForeignKey(PledgedriveWorker, verbose_name="Tech ID")
    segment_id = models.ForeignKey(PledgedriveSegment, verbose_name="Segment")
    pledge_amount = models.DecimalField(max_digits=6, decimal_places=2)
    pledge_note = models.CharField("Notes", max_length=125, blank=True)
    def __unicode__(self):
        return u'%s %s' % (self.pledge_amount, self.pledge_note)
    
